//
//  DBTabBarViewController.m
//  DianBa
//
//  Created by karl on 2018/8/20.
//  Copyright © 2018年 DianBa. All rights reserved.
//

#import "DBTabBarViewController.h"
#import "DBNavigationViewController.h"

#import "DBHomeViewController.h"
#import "DBClassificationViewController.h"
#import "DBShopCertViewController.h"
#import "DBMyViewController.h"

@interface DBTabBarViewController (){
    DBNavigationViewController *_homeNav; //首页
    DBNavigationViewController *_classificationNav; //分类
    DBNavigationViewController *_shopCertNav; //购物车
    DBNavigationViewController *_myNav; //我的
}

@end

@implementation DBTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.tabBar setBackgroundImage:[[UIImage alloc] init]];
    [self.tabBar setShadowImage:[[UIImage alloc] init]];
    [self.tabBar setSelectionIndicatorImage:[[UIImage alloc] init]];
    [self.tabBar setBackgroundColor:[UIColor colorWithString:MAIN_TABBAR_COLOR]];
    [self initViewControllers];
}

-(void)initViewControllers{
    DBHomeViewController *homeVC = [[DBHomeViewController alloc] init];
    _homeNav = [[DBNavigationViewController alloc] initWithRootViewController:homeVC];
    [_homeNav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [_homeNav.tabBarItem setTitle:@"首页"];
    [self settabbarTiTleColor:_homeNav unimage:@"tabbar_home_n" onimage:@"tabbar_home_h"];
    
    DBClassificationViewController *classificationViewController = [[DBClassificationViewController alloc] init];
    _classificationNav = [[DBNavigationViewController alloc] initWithRootViewController:classificationViewController];
    [_classificationNav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [_classificationNav.tabBarItem setTitle:@"分类"];
    [self settabbarTiTleColor:_classificationNav unimage:@"tabbar_message_n" onimage:@"tabbar_message_h"];
    
    DBShopCertViewController *shopCertVC = [[DBShopCertViewController alloc] init];
    _shopCertNav = [[DBNavigationViewController alloc] initWithRootViewController:shopCertVC];
    [_shopCertNav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [_shopCertNav.tabBarItem setTitle:@"购物车"];
    [self settabbarTiTleColor:_shopCertNav unimage:@"tabbar_order_n" onimage:@"tabbar_order_h"];
    
    DBMyViewController *myVC = [[DBMyViewController alloc] init];
    _myNav = [[DBNavigationViewController alloc] initWithRootViewController:myVC];
    [_myNav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [_myNav.tabBarItem setTitle:@"我的"];
    [self settabbarTiTleColor:_myNav unimage:@"tabbar_my_n" onimage:@"tabbar_my_h"];
    
    [self setViewControllers:@[_homeNav,_classificationNav,_shopCertNav,_myNav]];
}

-(void)settabbarTiTleColor:(UIViewController *)baritem  unimage:(NSString *)im1  onimage:(NSString *)im2{
    [baritem.tabBarItem setImage:[[UIImage imageNamed:im1]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [baritem.tabBarItem setSelectedImage:[[UIImage imageNamed:im2]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [[UITabBar appearance] setTintColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0]];
    [baritem.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    [baritem.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithString:MAIN_COLOR]} forState:UIControlStateSelected];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
